package com.netease.financial.common.util.preferences;

import android.support.annotation.NonNull;

/**
 * Created by wyf on 8/11/15.
 */
public class DownloadPreferencesHelper {
    private static final String PREFERENCES_FILE_NAME = PreferencesHelper.getFullPreferenceFileName("download");

    private static final String DOWNLOAD_ID_PREFIX = "download_id_";

    private static PreferencesHelper sPreferencesHelper;

    private static PreferencesHelper getPreferencesHelper() {
        if (sPreferencesHelper == null) {
            sPreferencesHelper = PreferencesHelper.newInstance(PREFERENCES_FILE_NAME);
        }
        return sPreferencesHelper;
    }

    public static void saveDownloadIdForUrl(String url, long downloadId) {
        getPreferencesHelper().putLong(getDownloadIdKey(url), downloadId);
    }

    public static long getDownloadIdForUrl(String url) {
        return getPreferencesHelper().getLong(getDownloadIdKey(url), -1L);
    }

    @NonNull
    private static String getDownloadIdKey(String url) {
        return DOWNLOAD_ID_PREFIX + url;
    }
}
